package homework.test;

//递归
public class Recursion {

    //阶乘
    public long factorial(int num) {
        if (num < 0) {
            throw new RuntimeException("你在干什么呀？负整数哪有阶乘？");
        }
        if (num == 0 || num == 1) {
            return 1L;//数学规定 0！和 1！都是1
        } else {
            return num * factorial(num - 1);//num 的阶乘等于 num * （num-1）的阶乘
        }
    }

    public static void main(String[] args) {

        Recursion recursion = new Recursion();
        int num = 6;
        long result = recursion.factorial(num);
        System.out.println(num + "的阶乘：" + result);

    }

}
